package org.car.world.controller;

import org.car.world.core.entily.MerchantsTable;
import org.car.world.service.impl.MerchantsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dell
 * @ClassName: MerchantsController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2018年11月6日
 */
@Controller("Merchants")
public class MerchantsController {


    @Autowired
    MerchantsServiceImpl merchantsService;

    @GetMapping("/home")
    public String toIndex() {
        return "index";
    }


    @GetMapping("/goto_login")
    public String toLogin() {
        return "appshoplogin";
    }

    @GetMapping("/goto_addshop")
    public String toAdd() {
        return "appshopadd";
    }

    @GetMapping("/goto_fuwutk")
    public String toFuwu() {
        return "fuwutk";
    }


    /**
     * @param @param  merchantsPhone
     * @param @param  merchantsShopname
     * @param @return 参数
     * @return String    返回类型
     * @throws
     * @Title: doLogin
     * @Description: 登陆方法
     */
    @GetMapping("/action_login")
    public String doLogin(String merchantsPhone, String merchantsShopname) {
        MerchantsTable merchats = merchantsService.loginMerchants(merchantsPhone, merchantsShopname);
        if (merchats != null) {
            System.err.println("登陆成功");
            return "index";
        }
        return "appshoplogin";
    }

    @ResponseBody
    @PostMapping("/action_addshop")
    public Boolean doAddshop(MerchantsTable merchant) {
        int result = merchantsService.insert(merchant);
        if (result > 0) {
            return true;
        }
        return false;
    }


}
